from django.views import generic
from django.utils import timezone

from .models import Article, Category, Tag


# Create your views here.
class HomePageView(generic.ListView):
    template_name = 'Blog/homepage.html'
    context_object_name = 'newest_article_list'

    def get_queryset(self):
        return Article.objects.filter(createTime__lte=timezone.now()).order_by('-createTime')[:5]

class IndexView(generic.ListView):
    template_name = 'Blog/index.html'
    context_object_name = 'article_list'
    paginate_by = 10

    def get_queryset(self):
        return Article.objects.all()

class DetailView(generic.DetailView):
    model = Article
    template_name = 'Blog/detail.html'

    # def get_queryset(self):
    #     return Article.objects.filter(createTime__lte=timezone.now())

class CategoryListView(generic.ListView):
    template_name = 'Blog/category.html'
    context_object_name = 'category_list'

    def get_queryset(self):
        return Category.objects.all()

class TagListView(generic.ListView):
    template_name = 'Blog/tag.html'
    context_object_name = 'tag_list'

    def get_queryset(self):
        return Tag.objects.all()


class CategoryView(generic.ListView):
    template_name = 'Blog/category.html'
    context_object_name = 'category_list'


class TagView(generic.ListView):
    template_name = 'Blog/tag.html'
    context_object_name = 'tag_list'
